set(FAASM_USER demo)

function(demo_func exec_name dir_path)
    faasm_func(${exec_name} ${dir_path})
    set(ALL_DEMO_FUNCS ${ALL_DEMO_FUNCS} ${exec_name} PARENT_SCOPE)
endfunction(demo_func)

function(demo_func_c exec_name dir_path)
    faasm_func_c(${exec_name} ${dir_path})
    set(ALL_DEMO_FUNCS ${ALL_DEMO_FUNCS} ${exec_name} PARENT_SCOPE)
endfunction(demo_func_c)

demo_func(argc_argv argc_argv.cpp)
demo_func(argc_argv_test argc_argv_test.cpp)
demo_func(backtrace backtrace.cpp)
demo_func(brk brk.cpp)
demo_func(calloc calloc.cpp)
demo_func(chain chain.cpp)
demo_func(chain_named_a chain_named_a.cpp)
demo_func(chain_named_b chain_named_b.cpp)
demo_func(chain_named_c chain_named_c.cpp)
demo_func(chain_output chain_output.cpp)
demo_func(chain_simple chain_simple.cpp)
demo_func(check_input check_input.cpp)
demo_func_c(c_example c_example.c)
demo_func(conf_flags conf_flags.cpp)
demo_func(cpp_example cpp_example.cpp)
#demo_func(curl_net curl_net.cpp)
demo_func(dummy dummy.cpp)
demo_func(echo echo.cpp)
demo_func(exit exit.cpp)
demo_func(fcntl fcntl.cpp)
demo_func(fibonacci fibonacci.cpp)
demo_func(file file.cpp)
demo_func(filedescriptor filedescriptor.cpp)
demo_func(fprintf fprintf.cpp)
demo_func(fread fread.cpp)
demo_func(fstat fstat.cpp)
demo_func(getcwd getcwd.cpp)
demo_func(getdents getdents.cpp)
demo_func(getenv getenv.cpp)
demo_func(getpwuid getpwuid.cpp)
demo_func(gettime gettime.cpp)
demo_func(heap heap.cpp)
demo_func(hello hello.cpp)
demo_func(increment increment.cpp)
demo_func(isatty isatty.cpp)
demo_func(listdir listdir.cpp)
demo_func(lock lock.c)
demo_func(log_difference log_difference.cpp)
demo_func(long_double long_double.cpp)
demo_func(malloc malloc.cpp)
demo_func(memcpy memcpy.cpp)
demo_func(memmove memmove.cpp)
demo_func(mmap mmap.cpp)
demo_func(mmap_big mmap_big.cpp)
demo_func(mmap_file mmap_file.cpp)
demo_func(munmap munmap.cpp)
demo_func(mt_difference mt_difference.cpp)
demo_func(new_obj new_obj.cpp)
demo_func(noop noop.c)
demo_func(optarg optarg.cpp)
demo_func(pi pi.cpp)
demo_func(print print.cpp)
demo_func(print_state print_state.cpp)
demo_func(ptr_ptr ptr_ptr.cpp)
demo_func(random random.cpp)
demo_func(scale_check scale_check.cpp)
demo_func(shared_file shared_file.cpp)
demo_func(simple simple.cpp)
demo_func(sizes sizes.cpp)
demo_func(sleep_long sleep_long.cpp)
demo_func(sleep_short sleep_short.cpp)
demo_func(snapshot_check snapshot_check.cpp)
demo_func(stackheap stackheap.cpp)
demo_func(stat stat.cpp)
demo_func(state_append state_append.cpp)
demo_func(state_async state_async.cpp)
demo_func(state_file state_file.cpp)
demo_func(state_offset state_offset.cpp)
demo_func(state_shared_write state_shared_write.cpp)
demo_func(state_shared_write_offset state_shared_write_offset.cpp)
demo_func(state_shared_read state_shared_read.cpp)
demo_func(state_shared_read_offset state_shared_read_offset.cpp)
demo_func(state_size state_size.cpp)
demo_func(stateop stateop.cpp)
demo_func(stdout stdout.cpp)
demo_func(stderr stderr.cpp)
demo_func(string string.cpp)
demo_func(sysconf sysconf.cpp)
demo_func(threads_local threads_local.cpp)
demo_func(threads_check threads_check.cpp)
demo_func(threads_dist threads_dist.cpp)
demo_func(threads_memory threads_memory.cpp)
demo_func(time time.cpp)
demo_func(time_of_day time_of_day.cpp)
demo_func(uname uname.cpp)
demo_func(va_arg va_arg.cpp)
demo_func(waitpid waitpid.cpp)
demo_func(x2 x2.cpp)
demo_func(zygote_check zygote_check.cpp)

# 23/09/2020 - removing simd
# WASM-only functions
if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
    # demo_func(eigen_vec eigen_vec.cpp)

    demo_func(emscripten_check emscripten_check.cpp)
    target_link_libraries(emscripten_check emscripten)

    # TODO - fix BLAS check function
    # include_directories(/usr/local/faasm/llvm-sysroot/include/clapack)
    # demo_func_c(blas_check blas_check.c)
    # target_link_libraries(blas_check ${FAASM_BLAS_LIBS})
endif()

faasm_dynamic_func(dynlink dynlink.cpp)
set(ALL_DEMO_FUNCS ${ALL_DEMO_FUNCS} dynlink)

# Custom target to group all the demo functions
add_custom_target(demo_all_funcs DEPENDS ${ALL_DEMO_FUNCS})

# Turn on WASM profiling
add_definitions(-DWASM_PROF=1)
demo_func(float_perf float_perf.cpp)

